/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin			*/
/*	Project:	GlbCloud			*/
/*	Author:		gong_libin			*/
/*	Date:		2012_01_29			*/
/*	File:		MrLog.cpp			*/
/********************************************************/

#include "MrLog.h"

CMrLog::CMrLog()
{
	m_pstLog = NULL;
}

CMrLog::~CMrLog()
{
	m_pstLog = NULL;
}

void CMrLog::MrLogFlush()
{
	fflush(m_pstLog);

	return;
}

void CMrLog::MrLogClose()
{
	if (NULL != m_pstLog) {
		fclose(m_pstLog);
		m_pstLog = NULL;
	}

	return;
}

int CMrLog::MrLogOpen(char* pszLog, char* pszMode)
{
	m_pstLog = fopen(pszLog, pszMode);
	if (NULL == m_pstLog) {
		MR_ERROR("%s\n", strerror(errno));
		return MR_FAILURE;
	}

	return MR_SUCCESS;
}

UINT CMrLog::MrLogRead(char* pszLine, UINT uiLength)
{
	UINT uiReturn = 0;

	if (NULL != m_pstLog) {
		uiReturn = fread((void*)pszLine, sizeof(char), uiLength, m_pstLog);
	}

	return uiReturn;
}

UINT CMrLog::MrLogWrite(char* pszLine, UINT uiLength)
{
	UINT uiReturn = 0;

	if (NULL != m_pstLog) {
		uiReturn = fwrite((void*)pszLine, sizeof(char), uiLength, m_pstLog);
	}

	return uiReturn;
}
